package RedPacket;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Leader extends User{
    public Leader(String name,float money) {
        super(name,money);
    }

    public ArrayList<Float> send( float totalMoney,int count){
        ArrayList<Float> list = new ArrayList();
        Random r = new Random();
        float bottle = totalMoney;
        DecimalFormat df = new DecimalFormat("#.##");

        //判断钱够不
        float leftMoney = getMoney();
        if (totalMoney > leftMoney){
            System.out.println("no enough money");
            return list; //return null arraylist
        }

        //将totalmoney分成count份 不等分
        for (int i = 0; i < count-1 ; i++) {
            int a = r.nextInt(5*count)+2;
            float each = bottle/a;
            each = Float.parseFloat(df.format(each));

            list.add(each);
            bottle -= each;

        }
        list.add(bottle);

        //扣钱
        setMoney(leftMoney-totalMoney);

        return list;
    }
}
